#include<iostream>
#include<string>
#include<regex>

using namespace std;

void test()
{
      ///
      string s("GET /legacy.cplusplus.comreference/login HTTP/1.1\r\n");
      smatch matches;
      //regex e("(HEAD|GET|POST|DELETE|PUT) ([^?]*).*");
      //regex e("(HEAD|GET|POST|DELETE|PUT) ([^?]*)\\?(.*) .*");
      regex e("(HEAD|GET|POST|DELETE|PUT) ([^?]*)(?:\\?(.*))? (HTTP/1\\.[01])(?:\n|\r\n)");
      bool ret=regex_match(s,matches,e);
      if(ret==false)    return;
      for(auto& str:matches)
            cout<<str<<endl;
}

int main()
{
      test();
      return 0;
}